﻿using MixingStation.LTWebService;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MixingStation
{
    public partial class WeightInfoForm : Form
    {
        private DateTime m_Start = DateTime.MinValue;
        private DateTime m_End = DateTime.MaxValue;
        //当前选择的物料ID
        private long m_MaterialId = 0;
        //当前选择的产地ID
        private long m_PlaceId = 0;
        //当前选择的供应商Id
        private long m_SupplierId = 0;
        //当前输入的车牌号
        private string m_CarCode = "";
        //当前选择的状态（）
        private int m_CarState = 7;
        //当前选择的打印状态
        private int m_Printed = 2;
        //当前选择的退货
        private int m_Back = 2;
        //当前选择的补录状态
        private int m_Record = 2;

        //绑定DataTable
        private DataTable m_BindDT = null;
        //车辆所属公司
        private int m_BelongCorpId = 2;
        
        //记录订单编号与订单的字典
        private Dictionary<string, purchaseOrderWS> m_PurchaseOrderDic = new Dictionary<string, purchaseOrderWS>();

        private List<materialWS> m_MaterialList = new List<materialWS>();
        public List<materialWS> MaterialList
        {
            set { m_MaterialList = value; }
        }
        private List<supplierWS> m_SupplierList = new List<supplierWS>();
        public List<supplierWS> SupplierList
        {
            set { m_SupplierList = value; }
        }

        private List<placeWS> m_PlaceList = new List<placeWS>();
        public List<placeWS> PlaceList
        {
            set { m_PlaceList = value; }
        }

        private List<DirectionInfo> m_DirectionList = new List<DirectionInfo>();
        public List<DirectionInfo> DirectionList
        {
            set { m_DirectionList = value; }
        }

        public WeightInfoForm()
        {
            InitializeComponent();
        }

        private void WeightInfoForm_Load(object sender, EventArgs e)
        {
            this.Size = Screen.GetWorkingArea(this).Size;
            this.Location = new Point(0, 0);
            m_BelongCorpId = int.Parse(ConfigurationManager.AppSettings["BelongCorpId"]);
            InitBinDT();
            InitCmbMaterial();
            InitCmbPlace();
            InitCmbSupplier();
            InitCmbPrinted();
            InitCmbIsBack();
            InitCmbIsReturn();
            InitCmbStatus();
            InitDateTime();
        }

        #region 初始化
        //初始化物料下拉框
        private void InitCmbMaterial()
        {
            try
            {
                if (m_MaterialList == null || m_MaterialList.Count == 0)
                    return;
                var list = new List<DataInfo>();
                list.Add(new DataInfo { Id = "", Value = "" });
                foreach (materialWS material in m_MaterialList)
                    list.Add(new DataInfo { Id = material.id.ToString(), Value = material.name });
                cmbMaterial.Properties.Items.Clear();
                foreach (DataInfo item in list)
                    cmbMaterial.Properties.Items.Add(item);
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化物料下拉框异常：" + ex.ToString());
            }
        }

        //初始化产地下拉框
        private void InitCmbPlace()
        {
            try
            {
                if (m_PlaceList == null || m_PlaceList.Count == 0)
                    return;
                var list = new List<DataInfo>();
                list.Add(new DataInfo { Id = "", Value = "" });
                foreach (placeWS place in m_PlaceList)
                    list.Add(new DataInfo { Id = place.id.ToString(), Value = place.name });
                cmbPlace.Properties.Items.Clear();
                foreach (DataInfo item in list)
                    cmbPlace.Properties.Items.Add(item);
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化产地下拉框异常：" + ex.ToString());
            }
        }

        //初始化供应商下拉框
        private void InitCmbSupplier()
        {
            try
            {
                if (m_SupplierList == null || m_SupplierList.Count == 0)
                    return;
                var list = new List<DataInfo>();
                list.Add(new DataInfo { Id = "", Value = "" });
                foreach (supplierWS supplier in m_SupplierList)
                    list.Add(new DataInfo { Id = supplier.id.ToString(), Value = supplier.name });
                cmbSupplier.Properties.Items.Clear();
                foreach (DataInfo item in list)
                    cmbSupplier.Properties.Items.Add(item);
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化供应商下拉框异常：" + ex.ToString());
            }
        }

        //初始化是否打印下拉框
        private void InitCmbPrinted()
        {
            try
            {
                var list = new List<DataInfo>();
                list.Add(new DataInfo { Id = "2", Value = "所有" });
                list.Add(new DataInfo { Id = "0", Value = "未打印" });
                list.Add(new DataInfo { Id = "1", Value = "已打印" });
                cmbPrinted.Properties.Items.Clear();
                foreach (DataInfo item in list)
                    cmbPrinted.Properties.Items.Add(item);
                cmbPrinted.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化打印状态下拉框异常：" + ex.ToString());
            }
        }

        //初始化是否退货下拉框
        private void InitCmbIsBack()
        {
            try
            {
                var list = new List<DataInfo>();
                list.Add(new DataInfo { Id = "2", Value = "所有" });
                list.Add(new DataInfo { Id = "1", Value = "是" });
                list.Add(new DataInfo { Id = "0", Value = "否" });
                cmbIsBack.Properties.Items.Clear();
                foreach (DataInfo item in list)
                    cmbIsBack.Properties.Items.Add(item);
                cmbIsBack.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化是否退货下拉框异常：" + ex.ToString());
            }
        }


        //初始化是否补录下拉框
        private void InitCmbIsReturn()
        {
            try
            {
                var list = new List<DataInfo>();
                list.Add(new DataInfo { Id = "2", Value = "所有" });
                list.Add(new DataInfo { Id = "1", Value = "是" });
                list.Add(new DataInfo { Id = "0", Value = "否" });
                cmbIsReturn.Properties.Items.Clear();
                foreach (DataInfo item in list)
                    cmbIsReturn.Properties.Items.Add(item);
                cmbIsReturn.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化是否补录下拉框异常：" + ex.ToString());
            }
        }


        //初始化状态下拉框
        private void InitCmbStatus()
        {
            try
            {
                var list = new List<DataInfo>();
                list.Add(new DataInfo { Id = "7", Value = "所有" });
                list.Add(new DataInfo { Id = "1", Value = "毛重称完" });
                list.Add(new DataInfo { Id = "2", Value = "收货完成" });
                list.Add(new DataInfo { Id = "3", Value = "皮重秤完" });
                list.Add(new DataInfo { Id = "4", Value = "完结" });
                list.Add(new DataInfo { Id = "5", Value = "毛重秤完与收货完成" });
                list.Add(new DataInfo { Id = "6", Value = "毛重秤完与皮重秤完" });

                cmbStatus.Properties.Items.Clear();
                foreach (DataInfo item in list)
                    cmbStatus.Properties.Items.Add(item);
                cmbStatus.SelectedIndex = 0;
            }
            catch (Exception ex)
            {
                LogHelper.error("初始化装车状态下拉框异常：" + ex.ToString());
            }
        }

        //初始化时间
        private void InitDateTime()
        {
            DateTime current = DateTime.Now;
            fromLastTime.EditValue = new DateTime(current.Year, current.Month, current.Day, 0, 0, 0);
            toLastTime.EditValue = new DateTime(current.Year, current.Month, current.Day, 23, 59, 59);
        }

        //初始化绑定的DT
        private void InitBinDT()
        {
            m_BindDT = new DataTable();
            m_BindDT.Columns.Add("SystemId");
            m_BindDT.Columns.Add("OrderCode");
            m_BindDT.Columns.Add("CarCode");
            m_BindDT.Columns.Add("MaterialCode");
            m_BindDT.Columns.Add("Material");
            m_BindDT.Columns.Add("SupplierCode");
            m_BindDT.Columns.Add("Supplier");
            m_BindDT.Columns.Add("Place");
            m_BindDT.Columns.Add("GrossWeight");
            m_BindDT.Columns.Add("Tareweight");
            m_BindDT.Columns.Add("BuckleWeight");
            m_BindDT.Columns.Add("BuckleReasons");
            m_BindDT.Columns.Add("NetWeight");
            m_BindDT.Columns.Add("DeliveryWeight");
            m_BindDT.Columns.Add("FirstWeightTime");
            m_BindDT.Columns.Add("FirstWeightMan");
            m_BindDT.Columns.Add("LastWeightTime");
            m_BindDT.Columns.Add("LastWeightMan");
            m_BindDT.Columns.Add("Status");
            m_BindDT.Columns.Add("Printed");
            m_BindDT.Columns.Add("IsBack");
            m_BindDT.Columns.Add("IsRecord");
            m_BindDT.Columns.Add("Remark");
        }
        #endregion

        #region 按钮事件
        private void btnSearch_Click(object sender, EventArgs e)
        {
            m_Start = Convert.ToDateTime(this.fromLastTime.EditValue);
            m_End = Convert.ToDateTime(this.toLastTime.EditValue);
            if (!string.IsNullOrEmpty(txtCarCode.Text.Trim()))
                m_CarCode = txtCarCode.Text.Trim();
            else
                m_CarCode = "";
            Search();
        }

        //数据补录
        private void btnAdd_Click(object sender, EventArgs e)
        {
            //管理员权限进行修改
            AdminConfirmForm adminForm = new AdminConfirmForm();
            adminForm.UserType = "管理员";
            if (adminForm.ShowDialog() != DialogResult.OK)
                return;
            WeightRecordAddForm form = new WeightRecordAddForm();
            form.MaterialList = m_MaterialList;
            form.SupplierList = m_SupplierList;
            form.PlaceList = m_PlaceList;
            form.DirectionList = m_DirectionList;
            if (form.ShowDialog() != DialogResult.OK)
                return;
            WeightRecordInfo recordInfo = form.CurrentRecordInfo;
            recordInfo.FirstWeightman = adminForm.User.employeeName;
            recordInfo.LastWeightman = adminForm.User.employeeName;

            try
            {
                purchaseCardWS purchaseCard = ServerCommonHelper.CreatePurchaseCardByRecord(adminForm.User, m_BelongCorpId, recordInfo);
                //数据补录增加标志位
                purchaseCard.isRecord = true;
                purchaseCard.isRecordSpecified = true;
                if (purchaseCard == null)
                {
                    MessageBox.Show(this, "构建采购信息错误，详细信息请参考日志文件!");
                    return;
                }
                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this, "数据补录失败，详细信息请参考日志文件!");
                    return;
                }
                MessageBox.Show(this, "数据补录成功!");
            }
            catch (Exception ex)
            {
                LogHelper.error("网络异常：" + ex.Message);
                MessageBox.Show(this, "网络异常，详细信息请参考日志文件!");
                return;
            }
            Search();
        }

        //修改毛重
        private void btnModifyGross_Click(object sender, EventArgs e)
        {
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, "请先选择数据!");
                return;
            }
            //若以上处的数据修改数据需联网状态
            DataGridViewRow selectedRows = GV_loadInfos.SelectedRows[0];
            long id = long.Parse(selectedRows.Cells["SystemIdColumn"].Value.ToString());
            string carCode = selectedRows.Cells["CarCodeColumn"].Value.ToString();
            int grossWeight = (int)decimal.Parse(selectedRows.Cells["GrossWeightColumn"].Value.ToString());
            //是否只有毛重称完，若只毛重称完需修改本地数据
            bool isGrossCompleted = selectedRows.Cells["StatusColumn"].Value.ToString() == "毛重称完" ? true : false;

            //是否有扣杂，若有，修改毛重后询问是否需要按之前比例重新更新扣杂
            int tareWeight = (int)decimal.Parse(selectedRows.Cells["TareWeightColumn"].Value.ToString());
            int buckleWeight = (int)decimal.Parse(selectedRows.Cells["BuckleWeightColumn"].Value.ToString());

            decimal newGrossWeight = 0;
            purchaseCardWS purchaseCard = null;
            bool isBuckle = false;
            try
            {
                purchaseCard = ServerCommonHelper.GetPurchaseCardByID(id);
                if (purchaseCard == null)
                {
                    MessageBox.Show(this, "未查询到ID：" + id + "的采购记录，详细信息请参考日志文件!");
                    return;
                }
                //管理员权限进行修改
                AdminConfirmForm adminForm = new AdminConfirmForm();
                adminForm.UserType = "管理员";
                if (adminForm.ShowDialog() != DialogResult.OK)
                    return;
                WeightModifyForm form = new WeightModifyForm(WeightModifyType.Gross);
                form.CarCode = carCode;
                form.OriginWeight = grossWeight;
                if (form.ShowDialog() != DialogResult.OK)
                    return;
                newGrossWeight = form.NewWeight;
                purchaseCard.grossWeight = newGrossWeight;
                purchaseCard.grossWeightSpecified = true;

                if (buckleWeight > 0)
                {
                    if (DialogResult.Yes == MessageBox.Show(this, "是否按原扣杂比例更新扣杂?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        purchaseCard.buckleWeight = Math.Round((buckleWeight * (newGrossWeight - tareWeight)) / (grossWeight - tareWeight));
                        purchaseCard.buckleWeightSpecified = true;
                        isBuckle = true;
                    }
                }
                purchaseCard.userId = Convert.ToInt64(adminForm.User.id);
                purchaseCard.userIdSpecified = true;

                purchaseCard.employeeId = Convert.ToInt64(adminForm.User.employeeId);
                purchaseCard.employeeIdSpecified = true;

                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this, "修改毛重失败，详细信息请参考日志文件!");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("修改毛重时网络异常：" + ex.ToString());
                MessageBox.Show(this, "网络异常，详细信息请参考日志文件!");
                return;
            }
            if (isGrossCompleted)
            {
                try
                {
                    string sql = "";
                    if (!isBuckle)
                    {
                        sql = "update WeightRecords set GrossWeight = " + newGrossWeight
                            + " where SystemId = '" + id + "' and UploadStatus = " + (int)UploadedEnum.FirstUploaded + " and IsPurchase = " + true;
                    }
                    else
                    {
                        sql = "update WeightRecords set GrossWeight = " + newGrossWeight + ", BuckleWeight = " + purchaseCard.buckleWeight 
                                                 + " where SystemId = '" + id + "' and UploadStatus = " + (int)UploadedEnum.FirstUploaded + " and IsPurchase = " + true;
                    }
                    if (!CommonHelper.DoOpreation(sql))
                    {
                        MessageBox.Show(this, "修改本地毛重数据失败,详细信息请参考日志文件!");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.error("修改本地毛重数据异常:" + ex.ToString());
                    MessageBox.Show(this, "修改本地毛重数据异常,详细信息请参考日志文件!");
                    return;
                }
            }
            MessageBox.Show(this," 修改毛重成功!");
            Search();
        }

        //修改皮重
        private void btnModifyTare_Click(object sender, EventArgs e)
        {
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, "请先选择数据!");
                return;
            }
            DataGridViewRow selectedRows = GV_loadInfos.SelectedRows[0];
            long id = long.Parse(selectedRows.Cells["SystemIdColumn"].Value.ToString());
            string carCode = selectedRows.Cells["CarCodeColumn"].Value.ToString();
            int tareWeight = (int)decimal.Parse(selectedRows.Cells["TareWeightColumn"].Value.ToString());

            int grossWeight = (int)decimal.Parse(selectedRows.Cells["GrossWeightColumn"].Value.ToString());
            int buckleWeight = (int)decimal.Parse(selectedRows.Cells["BuckleWeightColumn"].Value.ToString());

            decimal newTareWeight = 0;
            bool isBuckle = false;
            purchaseCardWS purchaseCard = null;
            try
            {
                purchaseCard = ServerCommonHelper.GetPurchaseCardByID(id);
                if (purchaseCard == null)
                {
                    MessageBox.Show(this, "未查询到ID：" + id + "的采购记录，详细信息请参考日志文件!");
                    return;
                }
                //（cardState：0进厂、1毛重称完、2收货完成、3皮重秤完、 4完结）
                if (purchaseCard.cardState < 3)
                {
                    MessageBox.Show(this, "该车辆尚未除皮，不能修改皮重!");
                    return;
                }
                //管理员权限进行修改
                AdminConfirmForm adminForm = new AdminConfirmForm();
                adminForm.UserType = "管理员";
                if (adminForm.ShowDialog() != DialogResult.OK)
                    return;
                WeightModifyForm form = new WeightModifyForm(WeightModifyType.Tare);
                form.CarCode = carCode;
                form.OriginWeight = tareWeight;
                if (form.ShowDialog() != DialogResult.OK)
                    return;

                newTareWeight = form.NewWeight;
                purchaseCard.tareWeight = newTareWeight;
                purchaseCard.tareWeightSpecified = true;

                if (buckleWeight > 0)
                {
                    if (DialogResult.Yes == MessageBox.Show(this, "是否按原扣杂比例更新扣杂?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                    {
                        purchaseCard.buckleWeight = Math.Round((buckleWeight * (grossWeight - newTareWeight)) / (grossWeight - tareWeight));
                        purchaseCard.buckleWeightSpecified = true;
                        isBuckle = true;
                    }
                }

                purchaseCard.userId = Convert.ToInt64(adminForm.User.id);
                purchaseCard.userIdSpecified = true;

                purchaseCard.employeeId = Convert.ToInt64(adminForm.User.employeeId);
                purchaseCard.employeeIdSpecified = true;

                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this, "修改皮重失败，详细信息请参考日志文件!");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("修改皮重时网络异常：" + ex.ToString());
                MessageBox.Show(this," 网络异常，详细信息请参考日志文件!");
                return;
            }
            //采购皮重
            MessageBox.Show(this," 修改皮重成功!");
            Search();
        }

        private void btnModifyOrder_Click(object sender, EventArgs e)
        {
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, "请先选择数据!");
                return;
            }
            //若以上处的数据修改数据需联网状态
            DataGridViewRow selectedRows = GV_loadInfos.SelectedRows[0];
            long id = long.Parse(selectedRows.Cells["SystemIdColumn"].Value.ToString());
            string materialCode = selectedRows.Cells["MaterialCodeColumn"].Value.ToString();
            string supplierCode = selectedRows.Cells["SupplierCodeColumn"].Value.ToString();
            bool isGrossCompleted = selectedRows.Cells["StatusColumn"].Value.ToString() == "毛重称完" ? true : false;

            purchaseCardWS purchaseCard = null;
            purchaseOrderWS updateOrder = null;
            try
            {
                purchaseCard = ServerCommonHelper.GetPurchaseCardByID(id);
                if (purchaseCard == null)
                {
                    MessageBox.Show(this, "未查询到ID：" + id + "的采购记录，详细信息请参考日志文件!");
                    return;
                }
                //管理员权限进行修改
                AdminConfirmForm adminForm = new AdminConfirmForm();
                adminForm.UserType = "散装装车";
                if (adminForm.ShowDialog() != DialogResult.OK)
                    return;
                PurchaseOrderSelectForm form = new PurchaseOrderSelectForm();
                form.MaterialArr = m_MaterialList.ToArray();
                form.SupplierArr = m_SupplierList.ToArray();
                form.MaterialCode = materialCode;
                form.SupplierCode = supplierCode;
                if (form.ShowDialog() != DialogResult.OK)
                    return;
                updateOrder = form.SelectPurchaseOrder;
                if (updateOrder == null)
                    return;

                purchaseCard.purchaseOrder = updateOrder;
                purchaseCard.material = updateOrder.material;
                purchaseCard.supplier = updateOrder.supplier;
                purchaseCard.place = updateOrder.place;
                purchaseCard.userId = Convert.ToInt64(adminForm.User.id);
                purchaseCard.userIdSpecified = true;

                purchaseCard.employeeId = Convert.ToInt64(adminForm.User.employeeId);
                purchaseCard.employeeIdSpecified = true;

                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this, "修改订单保存失败，详细信息请参考日志文件!");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("修改订单时网络异常：" + ex.ToString());
                MessageBox.Show(this, "网络异常，详细信息请参考日志文件!");
                return;
            }
            if (isGrossCompleted)
            {
                //对于未完结的（即一次称重有网的单据但未二次过磅或者二次过磅时无网的单据）
                try
                {
                    string newMaterialCode = updateOrder.material == null ? "" : updateOrder.material.code;
                    string newSupplierCode = updateOrder.supplier == null ? "" : updateOrder.supplier.code;
                    string newPlaceCode = updateOrder.place == null ? "" : updateOrder.place.code;

                    string sql = "update WeightRecords set OrderCode = '" + updateOrder.code
                        + "', MaterialCode = '" + newMaterialCode + "', SupplierCode = '" + newSupplierCode + "', PlaceCode = '" + newPlaceCode
                        + "' where SystemId = '" + id + "' and UploadStatus = " + (int)UploadedEnum.FirstUploaded + " and IsPurchase = true";
                    if (!CommonHelper.DoOpreation(sql))
                    {
                        MessageBox.Show(this," 本地修改订单信息失败,详细信息请参考日志文件!");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.error("本地修改订单信息异常:" + ex.ToString());
                    MessageBox.Show(this, "本地修改订单信息异常,详细信息请参考日志文件!");
                    return;
                }
            }
            MessageBox.Show(this," 修改订单成功!");
            Search();
        }

        private void btnModifyCarCode_Click(object sender, EventArgs e)
        {
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this," 请先选择数据!");
                return;
            }
            //若以上处的数据修改数据需联网状态
            DataGridViewRow selectedRows = GV_loadInfos.SelectedRows[0];
            long id = long.Parse(selectedRows.Cells["SystemIdColumn"].Value.ToString());
            string carCode = selectedRows.Cells["CarCodeColumn"].Value.ToString();
            bool isGrossCompleted = selectedRows.Cells["StatusColumn"].Value.ToString() == "毛重称完" ? true : false;

            string newCarCode = "";
            purchaseCardWS purchaseCard = null;
            try
            {
                purchaseCard = ServerCommonHelper.GetPurchaseCardByID(id);
                if (purchaseCard == null)
                {
                    MessageBox.Show(this, "未查询到ID：" + id + "的采购记录，详细信息请参考日志文件!");
                    return;
                }
                //管理员权限进行修改
                AdminConfirmForm adminForm = new AdminConfirmForm();
                adminForm.UserType = "散装装车";
                if (adminForm.ShowDialog() != DialogResult.OK)
                    return;
                CarCodeModifyForm form = new CarCodeModifyForm();
                form.CarCode = carCode;
                if (form.ShowDialog() != DialogResult.OK)
                    return;
                newCarCode = form.CarCode;
                carWS car = ServerCommonHelper.GetCar(newCarCode, 2, m_BelongCorpId);
                if (car == null)
                    return;
                purchaseCard.car = car;
                purchaseCard.userId = Convert.ToInt64(adminForm.User.id);
                purchaseCard.userIdSpecified = true;

                purchaseCard.employeeId = Convert.ToInt64(adminForm.User.employeeId);
                purchaseCard.employeeIdSpecified = true;

                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this,"修改车牌号失败，详细信息请参考日志文件!");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("修改车牌号时网络异常：" + ex.ToString());
                MessageBox.Show(this," 网络异常，详细信息请参考日志文件!");
                return;
            }
            if (isGrossCompleted)
            {
                try
                {
                    string sql = "update WeightRecords set CarCode = '" + newCarCode
                        + "' where SystemId = '" + id + "' and UploadStatus = " + (int)UploadedEnum.FirstUploaded + " and IsPurchase = true";
                    if (!CommonHelper.DoOpreation(sql))
                    {
                        MessageBox.Show(this," 修改车牌号失败,详细信息请参考日志文件!");
                        return;
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.error("本地修改车牌号异常:" + ex.ToString());
                    MessageBox.Show(this," 本地修改车牌号异常,详细信息请参考日志文件!");
                    return;
                }
            }
            MessageBox.Show(this," 修改车牌号成功!");
            Search();
        }

        //修改扣杂
        private void btnModifyBuckle_Click(object sender, EventArgs e)
        {
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this," 请先选择数据!");
                return;
            }
            DataGridViewRow selectedRows = GV_loadInfos.SelectedRows[0];
            long id = long.Parse(selectedRows.Cells["SystemIdColumn"].Value.ToString());
            string carCode = selectedRows.Cells["CarCodeColumn"].Value.ToString();
            int buckleWeight = (int)decimal.Parse(selectedRows.Cells["BuckleWeightColumn"].Value.ToString());

            decimal newBuckleWeight = 0;
            purchaseCardWS purchaseCard = null;
            try
            {
                purchaseCard = ServerCommonHelper.GetPurchaseCardByID(id);
                if (purchaseCard == null)
                {
                    MessageBox.Show(this," 未查询到ID：" + id + "的采购记录，详细信息请参考日志文件!");
                    return;
                }
                //（cardState：0进厂、1毛重称完、2收货完成、3皮重秤完、 4完结）
                if (purchaseCard.cardState < 3)
                {
                    MessageBox.Show(this," 该车辆尚未除皮，不能修改皮重!");
                    return;
                }
                //管理员权限进行修改
                AdminConfirmForm adminForm = new AdminConfirmForm();
                adminForm.UserType = "散装装车";
                if (adminForm.ShowDialog() != DialogResult.OK)
                    return;
                WeightModifyForm form = new WeightModifyForm(WeightModifyType.Buckle);
                form.CarCode = carCode;
                form.OriginWeight = buckleWeight;
                if (form.ShowDialog() != DialogResult.OK)
                    return;

                newBuckleWeight = form.NewWeight;
                purchaseCard.buckleWeight = newBuckleWeight;
                purchaseCard.buckleWeightSpecified = true;
                purchaseCard.userId = Convert.ToInt64(adminForm.User.id);
                purchaseCard.userIdSpecified = true;

                purchaseCard.employeeId = Convert.ToInt64(adminForm.User.employeeId);
                purchaseCard.employeeIdSpecified = true;

                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this," 修改扣杂失败，详细信息请参考日志文件!");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("修改扣杂时网络异常：" + ex.ToString());
                MessageBox.Show(this," 网络异常，详细信息请参考日志文件!");
                return;
            }
            //采购皮重
            MessageBox.Show(this," 修改扣杂成功!");
            Search();
        }

        //导出Excel
        private void btnExportExcel_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Execl files (*.xls)|*.xls";
            saveFileDialog.FilterIndex = 0;
            saveFileDialog.RestoreDirectory = true;
            saveFileDialog.CreatePrompt = true;
            saveFileDialog.Title = "Export Excel File To";
            DialogResult dr = saveFileDialog.ShowDialog();

            if (dr == DialogResult.Cancel)
                return;
            Stream myStream = saveFileDialog.OpenFile();

            if (CommonHelper.ExportExcel(myStream, this.GV_loadInfos))
                MessageBox.Show(this," 导出Excel成功！");
            else
                MessageBox.Show(this," 导出Excel失败！");
        }

        private void btnReprint_Click(object sender, EventArgs e)
        {
            //本地待上传数据磅单补打只有完结且修改本地的
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this," 请先选择数据!");
                return;
            }
            WeightRecordInfo weightRecordInfo = ServerCommonHelper.ConvertWeightRecordInfoByRow(GV_loadInfos.SelectedRows[0]);
            if (!weightRecordInfo.IsCompleted)
            {
                MessageBox.Show(this," 称重尚未完结,无法打印！");
                return;
            }
            try
            {
                using (LTCardAPIServiceClient client = new LTCardAPIServiceClient())
                {
                    bool isOnline = ServerCommonHelper.IsWebServiceAvaiable(client.Endpoint.Address.Uri);
                    AdminConfirmForm adminForm = new AdminConfirmForm();
                    adminForm.IsOnline = isOnline;
                    adminForm.UserType = "散装装车";
                    if (adminForm.ShowDialog() != DialogResult.OK)
                        return;
                    //联网时获取信息
                    purchaseCardWS printPurchaseCard = ServerCommonHelper.GetPurchaseCardByID(weightRecordInfo.SystemId);
                    if (printPurchaseCard == null)
                    {
                        MessageBox.Show(this, "根据Id:" + weightRecordInfo.SystemId + "未获取到采购记录");
                        return;
                    }
                    WeightRecordInfo printInfo = CommonHelper.ConvertWeightRecordInfo(printPurchaseCard);
                    printInfo.ReceiveName = ConfigurationManager.AppSettings["CorpName"].ToString();
                    //打印
                    if (!CommonHelper.Print(printInfo, adminForm.User.employeeName))
                    {
                        MessageBox.Show(this, "磅单补打失败，详细信息请参考日志文件！");
                        return;
                    }
                    resultWS result = client.setPurchaseCardPrintById(weightRecordInfo.SystemId);
                    if (!result.isSuccessful)
                    {
                        MessageBox.Show(this," 磅单补打失败:" + result.message);
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("磅单补打异常：" + ex.ToString());
            }
        }

        private void btnModifyBuckleReasons_Click(object sender, EventArgs e)
        {
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, " 请先选择数据!");
                return;
            }
            DataGridViewRow selectedRows = GV_loadInfos.SelectedRows[0];
            long id = long.Parse(selectedRows.Cells["SystemIdColumn"].Value.ToString());
            int buckleWeight = (int)decimal.Parse(selectedRows.Cells["BuckleWeightColumn"].Value.ToString());
            string buckleReasons = selectedRows.Cells["BuckleReasonsColumn"].Value.ToString();


            purchaseCardWS purchaseCard = null;
            try
            {
                purchaseCard = ServerCommonHelper.GetPurchaseCardByID(id);
                if (purchaseCard == null)
                {
                    MessageBox.Show(this, " 未查询到ID：" + id + "的采购记录，详细信息请参考日志文件!");
                    return;
                }
                //（cardState：0进厂、1毛重称完、2收货完成、3皮重秤完、 4完结）
                if (buckleWeight < 0)
                {
                    MessageBox.Show(this, " 该车辆尚未扣杂，不能修改扣杂原因!");
                    return;
                }
                //管理员权限进行修改
                AdminConfirmForm adminForm = new AdminConfirmForm();
                adminForm.UserType = "散装装车";
                if (adminForm.ShowDialog() != DialogResult.OK)
                    return;

                string newBuckleReasons = "";
                BuckleReasonsModifyForm form = new BuckleReasonsModifyForm();
                form.BuckleReasons = buckleReasons;
                if (form.ShowDialog() != DialogResult.OK)
                    return;
                newBuckleReasons = form.BuckleReasons;

                purchaseCard.buckleReasons = newBuckleReasons;
                purchaseCard.userId = Convert.ToInt64(adminForm.User.id);
                purchaseCard.userIdSpecified = true;

                purchaseCard.employeeId = Convert.ToInt64(adminForm.User.employeeId);
                purchaseCard.employeeIdSpecified = true;

                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this, " 修改扣杂原因失败，详细信息请参考日志文件!");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("修改扣杂时网络异常：" + ex.ToString());
                MessageBox.Show(this, " 网络异常，详细信息请参考日志文件!");
                return;
            }
            //采购皮重
            MessageBox.Show(this, " 修改扣杂原因成功!");
            Search();
        }
        #endregion

        #region 下拉框事件
        //选择的物料
        private void cmbMaterial_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbMaterial.SelectedItem == null || cmbMaterial.SelectedItem.ToString() == "")
              m_MaterialId = 0;
          else
              m_MaterialId = Convert.ToInt64(((DataInfo)cmbMaterial.SelectedItem).Id);
        }

        private void cmbPlace_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPlace.SelectedItem == null || cmbPlace.SelectedItem.ToString() == "")
                m_PlaceId = 0;
            else
                m_PlaceId = Convert.ToInt64(((DataInfo)cmbPlace.SelectedItem).Id);
        }

        //选择的供应商
        private void cmbSupplier_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbSupplier.SelectedItem == null || cmbSupplier.SelectedItem.ToString() == "")
                m_SupplierId = 0;
            else
                m_SupplierId = Convert.ToInt64(((DataInfo)cmbSupplier.SelectedItem).Id);
        }

        //选择打印状态
        private void cmbPrinted_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbPrinted.SelectedItem == null || cmbPrinted.SelectedItem.ToString() == "")
            {
                cmbPrinted.SelectedIndex = 0;
                m_Printed = 2;
            }
            else
            {
                string id = ((DataInfo)cmbPrinted.SelectedItem).Id;
                m_Printed = Convert.ToInt32(id);
            }
        }

        private void cmbIsBack_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbIsBack.SelectedItem == null || cmbIsBack.SelectedItem.ToString() == "")
            {
                cmbIsBack.SelectedIndex = 0;
                m_Back = 2;
            }
            else
            {
                string id = ((DataInfo)cmbIsBack.SelectedItem).Id;
                m_Back = Convert.ToInt32(id);
            }
        }

        private void cmbIsReturn_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbIsReturn.SelectedItem == null || cmbIsReturn.SelectedItem.ToString() == "")
            {
                cmbIsReturn.SelectedIndex = 0;
                m_Record = 2;
            }
            else
            {
                string id = ((DataInfo)cmbIsReturn.SelectedItem).Id;
                m_Record = Convert.ToInt32(id);
            }
        }

        //选择的装车状态
        private void cmbStatus_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cmbStatus.SelectedItem == null || cmbStatus.SelectedItem.ToString() == "")
            {
                cmbStatus.SelectedIndex = 0;
                m_CarState = 7;
            }
            else
            {
                string id = ((DataInfo)cmbStatus.SelectedItem).Id;
                m_CarState = Convert.ToInt32(id);
            }
        }
        #endregion

        #region 查询
        private void Search()
        {
            try
            {
                purchaseCardWS[] purchaseCardArr = null;
                using (LTCardAPIServiceClient client = new LTCardAPIServiceClient())
                {
                    purchaseCardArr = client.findPurchaseCards("", m_Start, m_End, m_SupplierId,
                        m_CarCode, m_MaterialId, m_CarState, m_Printed);
                }
                m_BindDT.Rows.Clear();
                this.GV_loadInfos.DataSource = m_BindDT;
                if (purchaseCardArr == null || purchaseCardArr.Length == 0)
                {
                    this.txtRecordNum.Text = "0";
                    this.txtGrossTotal.Text = "0";
                    this.txtTareTotal.Text = "0";
                    this.txtNetTotal.Text = "0";
                    this.txtBuckleTotal.Text = "0";
                    return;
                }
                purchaseCardWS[] tempArr = null;
                if (m_PlaceId == 0)
                {
                    //过滤是否退货，是否补录
                    if (m_Back != 2)
                    {
                        if (m_Record != 2)
                        {
                            var query = from temp in purchaseCardArr
                                        where temp.isBack == (m_Back == 1 ? true : false) && temp.isRecord == (m_Record == 1 ? true : false)
                                        select temp;
                            tempArr = query.ToArray<purchaseCardWS>();
                        }
                        else
                        {
                            var query = from temp in purchaseCardArr
                                        where temp.isBack == (m_Back == 1 ? true : false)
                                        select temp;
                            tempArr = query.ToArray<purchaseCardWS>();
                        }
                    }
                    else
                    {
                        if (m_Record != 2)
                        {
                            var query = from temp in purchaseCardArr
                                        where temp.isRecord == (m_Record == 1 ? true : false)
                                        select temp;
                            tempArr = query.ToArray<purchaseCardWS>();
                        }
                        else
                        {
                            tempArr = purchaseCardArr;
                        }
                    }
                }
                else
                {
                    //过滤是否退货，是否补录
                    if (m_Back != 2)
                    {
                        if (m_Record != 2)
                        {
                            var query = from temp in purchaseCardArr
                                        where temp.place.id == m_PlaceId && temp.isBack == (m_Back == 1 ? true : false) && temp.isRecord == (m_Record == 1 ? true : false)
                                        select temp;
                            tempArr = query.ToArray<purchaseCardWS>();
                        }
                        else
                        {
                            var query = from temp in purchaseCardArr
                                        where temp.place.id == m_PlaceId && temp.isBack == (m_Back == 1 ? true : false)
                                        select temp;
                            tempArr = query.ToArray<purchaseCardWS>();
                        }
                    }
                    else
                    {
                        if (m_Record != 2)
                        {
                            var query = from temp in purchaseCardArr
                                        where temp.place.id == m_PlaceId && temp.isRecord == (m_Record == 1 ? true : false)
                                        select temp;
                            tempArr = query.ToArray<purchaseCardWS>();
                        }
                        else
                        {
                            var query = from temp in purchaseCardArr
                                        where temp.place.id == m_PlaceId
                                        select temp;
                            tempArr = query.ToArray<purchaseCardWS>();
                        }
                    }
                }
                BindData(tempArr);
            }
            catch (Exception ex)
            {
                LogHelper.error("查询异常：" + ex.ToString());
                MessageBox.Show(this," 查询异常:" + ex.Message);
            }
        }

        //绑定列表
        private void BindData(purchaseCardWS[] purchaseCardArr)
        {
            long id;
            string orderCode = "";
            string carCode = "";
            string materialCode = "";
            string material = "";
            string supplierCode = "";
            string supplier = "";
            string place = "";
            decimal grossWeight = 0;
            decimal tareWeight = 0;
            decimal buckleWeight = 0;
            string buckleReasons = "";
            decimal netWeight = 0;
            decimal deliveryWeight = 0;
            DateTime firstWeightTime;
            string firstWeightMan = "";
            DateTime lastWeightTime;
            string lastWeightMan = "";
            string status = "";
            string printed = "";
            string isBack = "";
            string isRecord = "";
            string remark = "";

            int recordNum = 0;
            decimal grossWeightTotal = 0;
            decimal tareWeightTotal = 0;
            decimal buckleWeightTotal = 0;
            decimal netWeightTotal = 0;
            try
            {
                foreach (purchaseCardWS purchaseCard in purchaseCardArr)
                {
                    id = purchaseCard.id;
                    orderCode = purchaseCard.purchaseOrder == null ? "" : purchaseCard.purchaseOrder.code;
                    carCode = purchaseCard.car == null ? "" : purchaseCard.car.code;
                    materialCode = purchaseCard.material == null ? "" : purchaseCard.material.code;
                    material = purchaseCard.material == null ? "" : purchaseCard.material.name;
                    supplierCode = purchaseCard.supplier == null ? "" : purchaseCard.supplier.code;
                    supplier = purchaseCard.supplier == null ? "" : purchaseCard.supplier.name;
                    place = purchaseCard.place == null ? "" : purchaseCard.place.name;
                    grossWeight = (int)purchaseCard.grossWeight;
                    tareWeight = (int)purchaseCard.tareWeight;
                    buckleWeight = (int)purchaseCard.buckleWeight;
                    buckleReasons = purchaseCard.buckleReasons;
                    netWeight = grossWeight - tareWeight - buckleWeight;
                    deliveryWeight = (int)purchaseCard.deliveryWeight;

                    firstWeightTime = purchaseCard.firstWeightDate;
                    firstWeightMan = purchaseCard.weighman;
                    lastWeightTime = purchaseCard.secondWeightDate;
                    lastWeightMan = purchaseCard.tareWeightMan;

                    status = purchaseCard.cardState == 1 ? "毛重称完" : (purchaseCard.cardState == 2 ? "收货完成" 
                        : (purchaseCard.cardState == 3 ? "皮重称完" : "完结")); 
                    printed = purchaseCard.printed == true ? "已打印" : "未打印";
                    isBack = purchaseCard.isBack == true ? "是" : "否";
                    isRecord = purchaseCard.isRecord == true ? "是" : "否";
                    remark = purchaseCard.reasons;

                    m_BindDT.Rows.Add(id, orderCode, carCode, materialCode, material, supplierCode, supplier, place,
                        grossWeight, tareWeight, buckleWeight, buckleReasons, netWeight, deliveryWeight, firstWeightTime, firstWeightMan,
                        lastWeightTime, lastWeightMan, status, printed, isBack, isRecord, remark);

                    recordNum++;
                    grossWeightTotal += grossWeight;
                    tareWeightTotal += tareWeight;
                    buckleWeightTotal += buckleWeight;
                    netWeightTotal += netWeight;
                }
                this.GV_loadInfos.DataSource = m_BindDT;

                this.txtRecordNum.Text = recordNum.ToString();
                this.txtGrossTotal.Text = (grossWeightTotal / 1000).ToString();
                this.txtTareTotal.Text = (tareWeightTotal / 1000).ToString();
                this.txtNetTotal.Text = (netWeightTotal / 1000).ToString();
                this.txtBuckleTotal.Text = (buckleWeightTotal / 1000).ToString();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
        #endregion

        private void GV_loadInfos_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 0)//当单击复选框
            {
                if (Convert.ToString(GV_loadInfos.Rows[e.RowIndex].Cells[0].Value) == "true")
                {
                    GV_loadInfos.Rows[e.RowIndex].Cells[0].Value = "false";
                }
                else
                {
                    bool isUpLoad = GV_loadInfos.Rows[e.RowIndex].Cells["UploadColumn"].Value.ToString() == "已上传" ? true : false;
                    //如果该条记录已上传，则无需打钩
                    if (!isUpLoad)
                    {
                        string orderCode = Convert.ToString(GV_loadInfos.Rows[e.RowIndex].Cells["OrderCodeColumn"].Value);
                        //判断是否选择了采购订单
                        if (string.IsNullOrEmpty(orderCode))
                        {
                            MessageBox.Show(this," 上传数据前请先选择订单");
                            return;
                        }
                        GV_loadInfos.Rows[e.RowIndex].Cells[0].Value = "true";
                    }
                    else
                    {
                        MessageBox.Show(this," 该数据已上传，无需再勾选!");
                        return;
                    }
                }
            }
            //点击选择订单的界面
            else if (GV_loadInfos.Columns[e.ColumnIndex] is DataGridViewButtonColumn && e.RowIndex > -1)
            {
                string materialCode = GV_loadInfos.Rows[e.RowIndex].Cells["MaterialCodeColumn"].Value.ToString();
                string supplierCode = GV_loadInfos.Rows[e.RowIndex].Cells["SupplierCodeColumn"].Value.ToString();
                PurchaseOrderSelectForm form = new PurchaseOrderSelectForm();
                form.MaterialArr = m_MaterialList.ToArray();
                form.SupplierArr = m_SupplierList.ToArray();
                form.MaterialCode = materialCode;
                form.SupplierCode = supplierCode;
                if (DialogResult.OK == form.ShowDialog())
                {
                    purchaseOrderWS purchaseOrder = form.SelectPurchaseOrder;
                    GV_loadInfos.Rows[e.RowIndex].Cells["OrderCodeColumn"].Value = purchaseOrder.code;
                    if (!m_PurchaseOrderDic.ContainsKey(purchaseOrder.code))
                        m_PurchaseOrderDic.Add(purchaseOrder.code, purchaseOrder);
                }
            }
        }

        //行号
        private void GV_loadInfos_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X, e.RowBounds.Location.Y,
                GV_loadInfos.RowHeadersWidth - 4, e.RowBounds.Height);
            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
            GV_loadInfos.RowHeadersDefaultCellStyle.Font, rectangle,
            GV_loadInfos.RowHeadersDefaultCellStyle.ForeColor,
            TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

        //关闭
        private void btnClose_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }

        //送货重量
        private void btnModifySendWeight_Click(object sender, EventArgs e)
        {
            if (GV_loadInfos.SelectedRows.Count == 0)
            {
                MessageBox.Show(this, "请先选择数据!");
                return;
            }
            DataGridViewRow selectedRows = GV_loadInfos.SelectedRows[0];
            long id = long.Parse(selectedRows.Cells["SystemIdColumn"].Value.ToString());
            string carCode = selectedRows.Cells["CarCodeColumn"].Value.ToString();
            int deliveryWeight = (int)decimal.Parse(selectedRows.Cells["DeliveryWeightColumn"].Value.ToString());

            decimal newDeliveryWeight = 0;
            purchaseCardWS purchaseCard = null;
            try
            {
                purchaseCard = ServerCommonHelper.GetPurchaseCardByID(id);
                if (purchaseCard == null)
                {
                    MessageBox.Show(this, "未查询到ID：" + id + "的采购记录，详细信息请参考日志文件!");
                    return;
                }
                //（cardState：0进厂、1毛重称完、2收货完成、3皮重秤完、 4完结）
                if (purchaseCard.cardState < 3)
                {
                    MessageBox.Show(this, "该车辆尚未入库，不能修改送货重量!");
                    return;
                }
                //管理员权限进行修改
                AdminConfirmForm adminForm = new AdminConfirmForm();
                adminForm.UserType = "散装装车";
                if (adminForm.ShowDialog() != DialogResult.OK)
                    return;
                WeightModifyForm form = new WeightModifyForm(WeightModifyType.Delivery);
                form.CarCode = carCode;
                form.OriginWeight = deliveryWeight;
                if (form.ShowDialog() != DialogResult.OK)
                    return;

                newDeliveryWeight = form.NewWeight;
                purchaseCard.deliveryWeight = newDeliveryWeight;
                purchaseCard.deliveryWeightSpecified = true;
                purchaseCard.userId = Convert.ToInt64(adminForm.User.id);
                purchaseCard.userIdSpecified = true;

                purchaseCard.employeeId = Convert.ToInt64(adminForm.User.employeeId);
                purchaseCard.employeeIdSpecified = true;

                bool isSuccessful = ServerCommonHelper.UploadPurchaseCards(new purchaseCardWS[] { purchaseCard });
                if (!isSuccessful)
                {
                    MessageBox.Show(this, "修改送货重量失败，详细信息请参考日志文件!");
                    return;
                }
            }
            catch (Exception ex)
            {
                LogHelper.error("修改送货重量时网络异常：" + ex.ToString());
                MessageBox.Show(this, " 网络异常，详细信息请参考日志文件!");
                return;
            }
            //采购皮重
            MessageBox.Show(this, " 修改送货重量成功!");
            Search();
        }
    }
}
